//
//  PingLunOnZiXunTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/9.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "PingLunOnZiXunTableViewCell.h"

@implementation PingLunOnZiXunTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 用户头像
    self.userImageV = [[UIImageView alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 12 * kAdjustParamater, 50 * kAdjustParamater, 50 * kAdjustParamater)];
    self.userImageV.layer.cornerRadius = self.userImageV.width / 2;
    self.userImageV.layer.masksToBounds = YES;
 //   self.userImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    [self.contentView addSubview:_userImageV];
    
    //用户昵称
    self.userNickNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userImageV.right + 10 * kAdjustParamater, self.userImageV.top + 3 * kAdjustParamater, 150 * kAdjustParamater, 12 * kAdjustParamater)];
  //  self.userNickNameLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.userNickNameLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
    self.userNickNameLabel.textAlignment = NSTextAlignmentLeft;
    self.userNickNameLabel.font  = [UIFont fontWithName:@"ArialMT" size:k14Big];
    [self.contentView addSubview:_userNickNameLabel];
    
    // 发表时间
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userNickNameLabel.left, self.userNickNameLabel.bottom + 9 * kAdjustParamater, 200 * kAdjustParamater, 12 * kAdjustParamater)];
 //   self.timeLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.timeLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    self.timeLabel.font = [UIFont fontWithName:@"ArialMT" size:k14Big];
    [self.contentView addSubview:_timeLabel];
    
    // 点赞头像
    self.dianZanImageV = [[UIImageView alloc] initWithFrame:CGRectMake(315 * kAdjustParamater, 17 * kAdjustParamater, 20 * kAdjustParamater, 20 * kAdjustParamater)];
    self.dianZanImageV.userInteractionEnabled = YES;
    self.dianZanImageV.image = [UIImage imageNamed:@""];
    [self.contentView addSubview:_dianZanImageV];
    
    // 点赞人数
    self.dianZanCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.dianZanImageV.right + 7 * kAdjustParamater, self.dianZanImageV.top  + 3 * kAdjustParamater, 50 * kAdjustParamater, 14 * kAdjustParamater)];
//    self.dianZanCountLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
   // self.dianZanCountLabel.textColor = kYellowColor;
    self.dianZanCountLabel.textAlignment = NSTextAlignmentLeft;
    self.dianZanCountLabel.font = [UIFont systemFontOfSize:k15Big];
    [self.contentView addSubview:_dianZanCountLabel];
    
    // 垃圾桶
    self.laJiTongImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.dianZanImageV.left - 22 * kAdjustParamater, self.dianZanImageV.top + 1 * kAdjustParamater, 14 * kAdjustParamater, 18 * kAdjustParamater)];
    self.laJiTongImageV.userInteractionEnabled = YES;
    self.laJiTongImageV.image = [UIImage imageNamed:@"lajitonghuise-zixun"];
    [self.contentView addSubview:_laJiTongImageV];
    
    // 评论内容的灰色背景
    self.grayBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(71  * kAdjustParamater, self.userImageV.bottom - 10 * kAdjustParamater, 290 * kAdjustParamater, 40 * kAdjustParamater)];
    self.grayBackGroundView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_grayBackGroundView];
    
    // 评论
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(4 * kAdjustParamater, 5 * kAdjustParamater, 282 * kAdjustParamater, 30 * kAdjustParamater)];
 //   self.contentLabel.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.contentLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
    self.contentLabel.font = [UIFont fontWithName:@"ArialMT" size:k14Big];
    self.contentLabel.numberOfLines = 0;
    [self.grayBackGroundView addSubview:_contentLabel];
}

- (void)setModel:(ZiXunGeRenPingLunModel *)model
{
    [self.userImageV sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@""]];
    
    self.userNickNameLabel.text = model.nikename;
    self.timeLabel.text = model.created_at;
    self.dianZanCountLabel.text = model.like_num;
    self.contentLabel.text = model.content;
    // 自适应高度
    CGRect newFrameOfContentLabel = self.contentLabel.frame;
    newFrameOfContentLabel.size.height = [[NetStatusHandle shareHandle] adjustHeight:self.contentLabel.text size:13 width:282];
    self.contentLabel.frame = newFrameOfContentLabel;
    // 调整灰色背景的高度
    self.grayBackGroundView.frame = CGRectMake(self.grayBackGroundView.frame.origin.x, self.grayBackGroundView.frame.origin.y, self.grayBackGroundView.frame.size.width, self.contentLabel.height + 10 * kAdjustParamater);
    NSString *isLike = [NSString stringWithFormat:@"%@", model.is_liked];
  //  NSLog(@"isLike = %@, model.is_like = %@", isLike, model.is_liked);
    if ([isLike isEqualToString:@"1"]) {
        self.dianZanImageV.image = [UIImage imageNamed:@"dianzanguole-zixun"];
        self.dianZanCountLabel.textColor = kYellowColor;
    } else if ([isLike isEqualToString:@"0"]) {
        self.dianZanImageV.image = [UIImage imageNamed:@"weidianzan-zixun"];
        self.dianZanCountLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.15];
    }
  
    // 是否是自己
    NSString *isMySelf = [NSString stringWithFormat:@"%@", model.is_own];
    if ([isMySelf isEqualToString:@"1"]) {
        self.laJiTongImageV.hidden = NO;
    } else if ([isMySelf isEqualToString:@"0"]) {
        self.laJiTongImageV.hidden = YES;
    }
    
}

@end
